package com.kuang.controller;

import jdk.nashorn.api.scripting.ScriptUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpSession;

@Controller
public class loginController {
    @RequestMapping("/user/login")
    public String login(@RequestParam("Username") String username,
                        @RequestParam("Password") String password,
                        Model model,
                        HttpSession session) {
        if (!StringUtils.isEmpty(username) && "1".equals(password)) {
            session.setAttribute("loginUser",username);
            return "redirect:/main.html";
        } else {
            model.addAttribute("msg", "用戶名或者密碼錯誤");
            return "index";
        }

    }
    @RequestMapping("/user/loginout")
    public String loginOut(HttpSession httpSession) {
        httpSession.invalidate();
        return "redirect:/index.html";
    }
}
